﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class Form3DAlighment : System.Windows.Forms.Form
	{
		public Form3DAlighment(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.document = doc;
			base.Icon = Resource.YArchitechIcon;
		}

		private void button1_Click(object sender, EventArgs e)
		{
			if (this.comboBoxFS.Text != "" && this.hyTextBoxMinPipe.Text != "" && this.hyTextBoxWItdh.Text != "")
			{
				if (double.Parse(this.hyTextBoxWItdh.Text.ToString()) < 500.0)
				{
					this.hyTextBoxWItdh.Text = "500";
				}
				if (double.Parse(this.hyTextBoxMinPipe.Text.ToString()) < 500.0)
				{
					this.hyTextBoxMinPipe.Text = "500";
				}
				this.witdh = double.Parse(this.hyTextBoxWItdh.Text.ToString());
				this.minLength = double.Parse(this.hyTextBoxMinPipe.Text.ToString());
				this.Fs = this.comboBoxFS.SelectedItem.ToString();
				string[] array = new string[4];
				array[0] = this.comboBoxFS.SelectedItem.ToString();
				array[1] = this.hyTextBoxWItdh.Text;
				array[2] = this.hyTextBoxMinPipe.Text;
				if (this.rBSingle.Checked)
				{
					array[3] = "1";
					this.model = 1;
				}
				else if (this.rBlanch.Checked)
				{
					array[3] = "2";
					this.model = 2;
				}
				this.userSetting.Write3DAlighmentsPipeText(array);
				base.DialogResult = DialogResult.OK;
				return;
			}
			YJKMessageBox.Show("请确保输入不为空！");
		}

		private void button2_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void Form3DAlighment_Load(object sender, EventArgs e)
		{
			new System.Windows.Forms.Form().ShowInTaskbar = false;
			this.comboBoxFS.Items.Add("水管管径标注");
			this.comboBoxFS.Items.Add("水管外径标注");
			string[] array = this.userSetting.Get3DAlighmentsPipeText();
			this.comboBoxFS.SelectedItem = array[0];
			this.hyTextBoxWItdh.Text = array[1];
			this.hyTextBoxMinPipe.Text = array[2];
			if (array[3] == "1")
			{
				this.rBSingle.Checked = true;
				this.hyTextBoxMinPipe.Enabled = false;
			}
			else
			{
				this.rBlanch.Checked = true;
				this.hyTextBoxMinPipe.Enabled = true;
			}
			if (string.IsNullOrEmpty(this.comboBoxFS.Text) && this.comboBoxFS.Items != null && this.comboBoxFS.Items.Count > 0)
			{
				this.comboBoxFS.SelectedItem = this.comboBoxFS.Items[0];
			}
		}

		private List<FamilySymbol> getAllPipeTagFamilySymbol(Autodesk.Revit.DB.Document document)
		{
			List<FamilySymbol> list = new List<FamilySymbol>();
			foreach (Element element in ((IEnumerable<Element>)YJKElementFilter.GetElementsOfType(document, typeof(FamilySymbol), BuiltInCategory.OST_PipeTags).ToList<Element>()))
			{
				if (element is FamilySymbol)
				{
					list.Add(element as FamilySymbol);
				}
			}
			return list;
		}

		private void rBSingle_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rBSingle.Checked)
			{
				this.model = 1;
				this.hyTextBoxMinPipe.Enabled = false;
			}
		}

		private void rBlanch_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rBlanch.Checked)
			{
				this.model = 2;
				this.hyTextBoxMinPipe.Enabled = true;
			}
		}

		private void groupBox3_Enter(object sender, EventArgs e)
		{
		}

		private Document document;

		public double witdh;

		public double minLength;

		public string Fs = "";

		public int model = 1;

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
